package com.cat.dynamicPlanning;

/**
*   @description https://leetcode.cn/problems/longest-palindromic-substring/description/
*   @author 曲大人的喵
*   @create 2025/9/6 18:17
*   @since JDK17
*/

public class Solution88 {
    public String longestPalindrome(String s) {
        int n = s.length(), maxLen = 0, start = 0;
        boolean[][] dp = new boolean[n][n];
        for (int l = n - 1; l >= 0; l--) {
            for (int r = l; r < n; r++) {
                if (s.charAt(l) == s.charAt(r) && (r - l <= 1 || dp[l + 1][r - 1])) {
                    dp[l][r] = true;
                    if (r - l + 1 > maxLen) {
                        start = l;
                        maxLen = r - l + 1;
                    }
                }
            }
        }
        return s.substring(start, start + maxLen);
    }
}
